﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrimaryAlgorithm.HammingWeight
{
    class MainProjecet
    {
        static void Main(string[] args)
        {
            uint num = 11;
            Console.WriteLine(HammingWeight(3));
            Console.ReadKey();
        }
        public static int HammingWeight(uint n)
        {
            //右移
            int count = 0;
            for (int i = 0; i < 32; i++)
            {
                if ((n & 1) == 1)
                {
                    count++;
                }
                n = n >> 1;
            }
            return count;


            //为什么不行(LeetCode输入的是某一个值的二进制，而不是01字符串)
            //string uStr = n.ToString();
            //for (int i = 0; i < uStr.Length; i++)
            //{
            //    if (uStr[i] == 49)
            //    {
            //        count++;
            //    }
            //}
            //return count;
        }
    }
}
